/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.penguin.modules.field.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.penguin.modules.field.entity.FieldCustomerPos;
import com.thinkgem.penguin.modules.field.service.FieldCustomerPosService;

/**
 * 商家POS机管理维护Controller
 * @author 余小凡
 * @version 2015-05-21
 */
@Controller
@RequestMapping(value = "${adminPath}/field/fieldCustomerPos")
public class FieldCustomerPosController extends BaseController {

	@Autowired
	private FieldCustomerPosService fieldCustomerPosService;
	
	@ModelAttribute
	public FieldCustomerPos get(@RequestParam(required=false) String id) {
		FieldCustomerPos entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = fieldCustomerPosService.get(id);
		}
		if (entity == null){
			entity = new FieldCustomerPos();
		}
		return entity;
	}

	@RequiresPermissions("field:fieldCustomerPos:view")
	@RequestMapping(value = {"userInfo", ""})
	public String userInfo(HttpServletRequest request, HttpServletResponse response) {
		return "modules/field/userIndex";
	}
	
	@RequiresPermissions("field:fieldCustomerPos:view")
	@RequestMapping(value = {"list", ""})
	public String list(FieldCustomerPos fieldCustomerPos, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<FieldCustomerPos> page = fieldCustomerPosService.findPage(new Page<FieldCustomerPos>(request, response), fieldCustomerPos); 
		model.addAttribute("page", page);
		return "modules/field/fieldCustomerPosList";
	}

	@RequiresPermissions("field:fieldCustomerPos:view")
	@RequestMapping(value = "form")
	public String form(FieldCustomerPos fieldCustomerPos, Model model) {
		model.addAttribute("fieldCustomerPos", fieldCustomerPos);
		return "modules/field/fieldCustomerPosForm";
	}

	@RequiresPermissions("field:fieldCustomerPos:edit")
	@RequestMapping(value = "save")
	public String save(FieldCustomerPos fieldCustomerPos, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, fieldCustomerPos)){
			return form(fieldCustomerPos, model);
		}
		fieldCustomerPosService.save(fieldCustomerPos);
		addMessage(redirectAttributes, "保存商家POS机管理维护成功");
		return "redirect:"+Global.getAdminPath()+"/field/fieldCustomerPos/list?repage";
	}
	
	@RequiresPermissions("field:fieldCustomerPos:edit")
	@RequestMapping(value = "delete")
	public String delete(FieldCustomerPos fieldCustomerPos, RedirectAttributes redirectAttributes) {
		fieldCustomerPosService.delete(fieldCustomerPos);
		addMessage(redirectAttributes, "删除商家POS机管理维护成功");
		return "redirect:"+Global.getAdminPath()+"/field/fieldCustomerPos/list?repage";
	}

}